﻿using System;
using System.Collections.Generic;
using System.Text;
using TSVNAddin.TSVN;

namespace TSVNAddin.Core
{
	public class CheckoutCommand : ICommand
	{
		private readonly TortoiseProcExecutor _TortoiseProcExecutor;
		private readonly WorkingContext _WorkingContext;

		public CheckoutCommand(TortoiseProcExecutor tortoiseProcExecutor, WorkingContext workingContext)
		{
			_TortoiseProcExecutor = tortoiseProcExecutor;
			_WorkingContext = workingContext;
		}

		public void Execute()
		{
			_TortoiseProcExecutor.Exec(TortoiseProcCommandType.Checkout, _WorkingContext.GetWorkingRoot());
			_WorkingContext.ResetWorkingCopy();
		}

		public CommandStatus QueryStatus()
		{
			if (!_WorkingContext.CanExecuteCheckout())
				return CommandStatus.Disabled;

			return CommandStatus.Enabled;
		}
	}
}
